package com.dmwork.service.work.controller.front.me.feign;

import com.dmwork.common.base.result.R;
import com.dmwork.service.work.entity.Work;
import com.dmwork.service.work.service.WorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(description = "个人作品服务调用接口")
@RestController
@RequestMapping("/front/dm_work/work/me/feign")
public class FrontMeFeignWorkController {

    @Autowired
    private WorkService workService;

    @ApiOperation("更新作品收藏数服务接口")
    @PutMapping("modify_work_collect_count/{workId}/{flag}")
    public R modifyWorkCollectCount(@PathVariable("workId") String workId, @PathVariable("flag") Integer flag) {

        Work work = workService.getById(workId);
        //如果flag==1，则作品收藏数+1
        if (flag==1) {
            work.setCollectCount(work.getCollectCount()+1);
            workService.updateById(work);
        }else if (flag==0) { // 如果flag==0，则作品收藏数-1
            work.setCollectCount(work.getCollectCount()-1);
            workService.updateById(work);
        }
        return R.ok();
    }

    @ApiOperation("批量更新作品收藏数服务接口")
    @PutMapping("modify_batch_work_collect_count/{flag}")
    public R modifyBatchWorkCollectCount(@RequestBody List<String> workIdList, @PathVariable("flag") Integer flag) {
        workService.modifyBatchWorkCollectCount(workIdList, flag);
        return R.ok();
    }

}
